<html>
<script src="jquery.js"></script>
<script type="text/javascript" language="JavaScript">
var deviceId = 0;
var startPos = null;
function loadApp()
{
	$.post
	(
		'http://ruby.ils.unc.edu/~abapat/app/getId.php',
		function(id)
		{
			deviceId = id;
			printLocation(id);
		}
	)

}

function printLocation(id)
{
	navigator.geolocation.getCurrentPosition(
		function(position) {
			startPos = position;
			lat = startPos.coords.latitude;
			lon = startPos.coords.longitude;
			document.getElementById("location").innerHTML = "<br/><br/>lat: " + lat + "; <br/> long: " + lon;
			saveToDatabase(lat, lon); 
		});
		
	window.setTimeout("printLocation()",3000);
}

function saveToDatabase(lat1, lon1)
{
	$.post
	(
		'http://ruby.ils.unc.edu/~abapat/app/setLocation.php',
		{
			id: deviceId,
			lat: lat1,
			lon: lon1
		},
		function(data)
		{
			// do nothing
		}
	);
}


</script>
<body onload="loadApp()">
<p id="location">
</p>
</body>
</html>